package cn.anquing.demo.elasticsearch.demo.es;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.util.Date;

/**
 * @author wangqq65
 * @since 2021/4/20 17:20
 */

/**
 * useServerConfiguration=true, createIndex = false ，作用是不需要自动生成index，实际中都是ES中本来就有数据
 */
@Data
@Document(indexName = "blog",
        useServerConfiguration=true,
        createIndex = false)
public class EsBlog implements Serializable {

    @Id
    private Long id;

    @Field(type = FieldType.Text)
    private String author;

    @Field(type = FieldType.Text)
    private String title;

    @Field(type = FieldType.Text)
    private String content;

    /**
     * ES使用的是UTC时间，所以在时间查询方便在查询时要指定time_zone,
     * 针对ES返回的时间也要转化成CST
     */
    @Field(type = FieldType.Date,format = DateFormat.custom,
            pattern = "uuuu-MM-dd HH:mm:ss || uuuu-MM-dd || epoch_millis")
    private Date createTime;

    @Field(type = FieldType.Date,format = DateFormat.custom,
            pattern = "uuuu-MM-dd HH:mm:ss || uuuu-MM-dd || epoch_millis")
    private Date updateTime;

}
